<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=utf-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <jsp:include page="common.jsp"/>
    <!-- 引入首页的css 文件 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/index.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/assets/css/register.css">
</head>

<body>
<!-- 头部 -->
<jsp:include page="header.jsp"/>
<!-- 头部 end -->
<div class="rg_layout">
    <div class="rg_form clearfix">
        <div class="rg_form_left">
            <p>新用户注册</p>
        </div>
        <div class="rg_form_center">

            <!--注册表单-->
            <div id="registerForm">
                <!--提交处理请求的标识符-->
                <input type="hidden" name="action" value="register">
                <table style="margin-top: 25px;">
                    <tr>
                        <td class="td_left">
                            <label for="username">用户名</label>
                        </td>
                        <td class="td_right">
                            <input type="text" id="username" name="username" placeholder="请输入账号">
                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">
                            <label for="password">密码</label>
                        </td>
                        <td class="td_right">
                            <input type="text" id="password" name="password" placeholder="请输入密码">
                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">
                            <label for="email">Email</label>
                        </td>
                        <td class="td_right">
                            <input type="text" id="email" name="email" placeholder="请输入Email">
                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">
                            <label for="name">姓名</label>
                        </td>
                        <td class="td_right">
                            <input type="text" id="name" name="name" placeholder="请输入真实姓名">
                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">
                            <label for="telephone">手机号</label>
                        </td>
                        <td class="td_right">
                            <input type="text" id="telephone" name="telephone" placeholder="请输入您的手机号">
                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">
                            <label for="sex">性别</label>
                        </td>
                        <td class="td_right gender">
                            <input type="radio" id="sex" name="sex" value="男" checked> 男
                            <input type="radio" name="sex" value="女"> 女
                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">
                            <label for="birthday">出生日期</label>
                        </td>
                        <td class="td_right">
                            <input type="date" id="birthday" name="birthday" placeholder="年/月/日">
                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">
                            <label for="check">验证码</label>
                        </td>
                        <td class="td_right check">
                            <input type="text" id="check" name="check" class="check">
                            <img src="${pageContext.request.contextPath}/captcha" height="32px" id="verCode" alt=""
                                 onclick="changeVerCode()">

                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">
                        </td>
                        <td class="td_right check">
                            <input type="button" class="submit" value="注册" onclick="result()">
                            <span id="msg" style="color: red;"></span>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="rg_form_right">
            <p>
                已有账号？
                <a href="login.jsp">立即登录</a>
            </p>
        </div>
    </div>
</div>
<!-- 底部 -->
<jsp:include page="footer.jsp"/>
<script>
    function changeVerCode() {
        $("#verCode").attr('src', '${pageContext.request.contextPath}/captcha?time' + new Date());
    }

    function result() {
        var username = $("#username").val();
        var password = $("#password").val();
        var email = $("#email").val();
        var name = $("#name").val();
        var telephone = $("#telephone").val();
        var sex = $("#sex").val();
        var birthday = $("#birthday").val();
        var check = $("#check").val();
        $.ajax({
            url: "${pageContext.request.contextPath}/user/register",
            type: "post",
            dataType: "json",
            data: {
                username: username,
                password: password,
                email: email,
                name: name,
                telephone: telephone,
                sex: sex,
                birthday: birthday,
                check: check,
            },
            success: function (data) {
                alert(data.info);
                if (data.code == 0) {
                    location.reload();
                }
                if (data.code == 1) {
                    location.href = "login.jsp";
                }
            },
            error: function () {
                alert("网络超时，请重试");
            }
        });
    }
</script>
</body>

</html>